﻿<style>
    .pt20 {
        padding-top: 0px;
    }

    .jg-right {
        padding-top: 20px;
    }

    .jinyong {
        color: orangered;
    }
</style>
<div ms-controller="YGINDEX">
    <div class="jg-left pull-left ft14">
        <p class="mb10 ft16 padding20 c999"><i class="iconfont icon-zuzhi ft14 mr5"></i>组织机构</p>
        <script type="avalon" id="tmpltree">
            <li ms-repeat-branch="branch.ChildBranch">
                <div class="jg-item" ms-class-1="active:branch.DeptCode==SelDeptItem.DeptCode">
                    <b ms-click="BranchClick(branch,$event)">
                        <i class="caret" ms-click="BranchToggle(this,$event)" ms-class-1="active:branch.ChildBranch.size()>0"></i>
                        <span class="jg-name">{{ConBranch(branch.DeptName)}}</span><!--<i class="jg-number ft12 c999">（8人）</i>-->
                    </b>
                    <div class="jg-sz">
                        <i class="dropdown-toggle jh c999" data-toggle="dropdown" aria-expanded="true">+</i>
                        <ul class="dropdown-menu  menu-tip animated fadeInRight c666">
                            <li>
                                <a ms-click="OpenBranch(1,branch)">添加子部门</a>
                            </li>
                            <li>
                                <a ms-click="OpenBranch(2,branch)">修改部门</a>
                            </li>
                            <li ms-if="branch.DeptRoot!=-1">
                                <a ms-click="DelDept(branch,$event)">删除</a>
                            </li>
                            <li>
                                <a ms-click="OpenSetLeader()">设置部门负责人</a>
                            </li>
                            <li ms-if="branch.DeptRoot!=-1">
                                <a ms-click="setBranch(branch)">部门可见范围</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <ul class="children-list" ms-include="'tmpltree'"></ul>
            </li>
        </script>
        <ul class="jg-list-box">
            <li ms-repeat-branch="BranchListData">
                <div class="jg-item" ms-class-1="active:branch.DeptCode==SelDeptItem.DeptCode">
                    <b ms-click="BranchClick(branch,$event)">
                        <i class="caret" ms-click="BranchToggle(this,$event)" ms-class-1="active:branch.ChildBranch.size()>0"></i>
                        <span class="jg-name">{{ConBranch(branch.DeptName)}}</span>
                    </b>
                    <div class="jg-sz">
                        <i class="dropdown-toggle jh c999" data-toggle="dropdown" aria-expanded="true">+</i>
                        <ul class="dropdown-menu  menu-tip animated fadeInRight c666">
                            <li>
                                <a ms-click="OpenBranch(1,branch)">添加子部门</a>
                            </li>
                            <li>
                                <a ms-click="OpenBranch(2,branch)">修改部门</a>
                            </li>
                            <li ms-if="branch.DeptRoot!=-1">
                                <a ms-click="DelDept(branch,$event)">删除</a>
                            </li>
                            <li>
                                <a ms-click="OpenSetLeader()">设置部门负责人</a>
                            </li>
                            <li ms-if="branch.DeptRoot!=-1">
                                <a ms-click="setBranch(branch)">部门可见范围</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <ul class="children-list" ms-include="'tmpltree'"></ul>
            </li>
        </ul>
    </div>
    <div class="jg-right ">
        <div class="btn-add">
            <button type="button" class="btn btn-info" ms-click="TBGZSTATUS()" ms-if="CompanyData.IsUseWX=='Y'">同步关注状态</button>
            <button type="button" class="btn btn-info" ms-click="UserAdd()"><i class="iconfont icon-jiahao ft12 mr5"></i>添加员工</button>
            <button type="button" class="btn btn-info" ms-click="UserImport()"><i class="iconfont icon-dr ft12 mr5"></i>批量导入</button>
            <a class="btn btn-info" ms-click="dcyg()"><i class="iconfont icon-dc ft12 mr5"></i>导出</a>

        </div>
        <!-- 机构管理详情 -->
        <div class="jg-cont ft14">

            <div class=" ml15" style="position: relative">

                <a class="c-default dropdown-toggle ft16" data-toggle="dropdown">
                    <i class="iconfont icon-bookmark c-default mr5"></i>{{SelDeptItem.DeptName}}<span class="caret ml10"></span>
                </a>
                <ul class="dropdown-menu  animated fadeInRight">
                    <li>
                        <a ms-click="OpenBranch(1,SelDeptItem)">添加子部门</a>
                    </li>
                    <li>
                        <a ms-click="OpenBranch(2,SelDeptItem)">修改部门</a>
                    </li>
                    <li ms-if="SelDeptItem.DeptRoot!=-1">
                        <a ms-click="DelDept(SelDeptItem,$event)">删除</a>
                    </li>
                    <li>
                        <a ms-click="OpenSetLeader()">设置部门负责人</a>
                    </li>
                    <li ms-if="SelDeptItem.DeptRoot!=-1">
                        <a ms-click="setBranch(SelDeptItem)">部门可见范围</a>
                    </li>

                </ul>
            </div>
            <div class="detail-con">

                <div class="detail-item">
                    <span class="item-tit" ms-visible="SelDeptItem.DeptDesc">部门描述：</span>
                    <div class="item-con">{{SelDeptItem.DeptDesc}}</div>
                </div>
                <div class="detail-item">
                    <span class="item-tit">部门负责人：</span>
                    <div class="item-con">{{SelDeptItem.BranchLeader?ComFunJS.convertuser(SelDeptItem.BranchLeader):""}}<a ms-click="OpenSetLeader()" class="text-primary" style="margin-left: 20px;">设置</a></div>
                </div>
                <div class="detail-item" ms-visible="SelDeptItem.RoomCode">
                    <span class="item-tit">房间号：</span>
                    <div class="item-con">{{SelDeptItem.RoomCode}}</div>
                </div>
            </div>
        </div>
        <!--  -->
        <div class="default-tab ft14">
            <div class="ml15 pb20 mr15">
                <button type="button" class="btn btn-info" ms-click="UPDATEPLUser()">分配部门</button>
                <button type="button" class="btn btn-info" ms-click="OpenPLModify()">重置密码</button>
                <button type="button" class="btn btn-info" style="float: right" data-toggle="modal" data-target="#myselfModal">自定义显示</button>
                <div class="input-group ml15" style="width: 295px; float: right; margin-right: 20px;">
                    <input type="search" class="form-control" placeholder="搜索姓名，账号，部门，手机号" ms-duplex="searchContent">
                    <span class="input-group-addon" ms-click="GetLIST()">搜索</span>
                </div>

            </div>
            <div class="default-tab ft14 pt20 table-responsive">
                <table class="table table-striped  table-hover" id="branchTab">
                    <thead>
                        <tr>
                            <th class="tc">
                                <div class="icheckbox_square-blue">
                                    <span class="iconfont icon-check ft12"></span>
                                </div>
                            </th>
                            <th>姓名</th>
                            <th ms-repeat-im="ShowColumns" ms-visible="im.IsSel">{{im.ColText}}</th>
                            <th style="width: 120px;">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ms-repeat-item="UserData">
                            <td class="tc">
                                <div class="icheckbox_square-blue" ms-attr-user="item.UserName" ms-click="ViewForm('XTGL_YGGL',item.UserName,$event)">
                                    <span class="iconfont icon-check ft12"></span>
                                </div>
                            </td>
                            <td style="min-width: 120px;" ms-click="ViewForm('XTGL_YGGL',item.UserName,$event)" class="lk">
                                <span ms-if="item.IsUse=='N'" class="ico-radius-r"></span>
                                <span ms-if="item.IsUse=='Y'" class="ico-radius-r color-greed"></span>{{item.UserRealName}}
                            </td>

                            <td ms-repeat-im="ShowColumns" style="min-width: 120px;" ms-visible="im.IsSel">{{ComFunJS.FnFormat(item[im.ColName],im)|html}}</td>
                            <td>
                                <div style="position: relative" class="bg-fun">
                                    <span class="iconfont icon-shanchu  c-default cursor tip mr5" title="删除用户" ms-click="DelUser(item);" ms-if="item.isSupAdmin!='Y'"></span>
                                    <span class="iconfont icon-bianji  c-default cursor tip mr5" title="编辑" ms-click="EditUser(item);"></span>
                                    <span class="iconfont icon-khgl  c-default cursor tip mr5" ms-click="OpenUserLead(item);" title="设置上级"></span>
                                    <span class="iconfont icon-qidong   cursor  mr5" ms-class-1="jinyong:item.IsUse=='Y'" ms-click="EditIsUse(item);" ms-attr-title="item.IsUse=='Y'?'禁用':'启用'"></span>


                                </div>

                            </td>

                        </tr>
                    </tbody>
                    <tfoot>
                        <tr ms-if="isnull">
                            <td class="tc"></td>
                            <td>暂无数据</td>
                        </tr>
                    </tfoot>
                </table>
            </div>
            <div class="ui-datatable-page ft14 pl20">
                <div ms-if="UserData.size()!=0"><span class="ico-radius-r"></span>禁止登陆</div>
                <div ms-if="UserData.size()!=0"><span class="ico-radius-r color-red"></span>未激活</div>
                <div ms-if="UserData.size()!=0"><span class="ico-radius-r color-greed"></span>正常</div>
                <div id="pageDiv" ms-visible="model.page.total>model.pageNum[0].num" class="pull-right"></div>
                <div class="pull-right" ms-visible="UserData.size()!=0">
                    <span>共{{model.page.total}}条记录</span>
                    <span ms-visible="model.page.total>model.pageNum[0].num">选择每页条数
                        <select style="height: 25px; width: 50px;" ms-change="selNum(this.value)" ms-duplex="model.page.pagecount">
                            <option ms-repeat-pg="pageNum" ms-attr-value="pg.num" ms-attr-selected="pg.num==model.page.pagecount?'selected':''">{{pg.num}}</option>
                        </select>
                    </span>
                </div>
            </div>

        </div>
    </div>
    <div class="modal" id="BranchLeadModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">设置部门负责人</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">负责人</label>
                            <input type="text" class="form-control szhl_getPeoples" ms-duplex="branchLeader" style="display: none" signle="Y" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="SetLeader()"><i class="fa fa-spinner fa-spin" style="display: none"></i>保存</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal" id="UserLeadModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">设置上级</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label">上级人员</label>
                            <input type="text" class="form-control szhl_getPeoples" ms-duplex="userLead" style="display: none" signle="Y" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="SetUserLeader()"><i class="fa fa-spinner fa-spin" style="display: none"></i>保存</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="ReSetPassWordModal" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">重置密码</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label"><span class="Required">*</span>新密码</label>
                            <input type="password" class="form-control szhl_require" style="width: 200px" id="newPwd" placeholder="请输入新密码" />
                        </div>
                        <div class="form-group">
                            <label class="col-xs-4 control-label"><span class="Required">*</span>确认密码</label>
                            <input type="password" class="form-control szhl_require" style="width: 200px" id="newPwd2" placeholder="请输入确认密码" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="ModifyPwd(this)"><i class="fa fa-spinner fa-spin" style="display: none"></i>确&nbsp;&nbsp;认</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="ModifyBranchModal" role="dialog">
        <div class="modal-dialog" role="document" style="width: 500px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">编辑部门</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-xs-4 control-label text-right">上级部门</label>
                            <div class="col-xs-6">
                                <input type="text" class="form-control" id="pname" readonly="readonly" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="branchName" class="col-xs-4 control-label text-right">部门名称</label>
                            <div class="col-xs-6">
                                <input type="text" class="form-control" id="branchName" ms-duplex="BranchData.DeptName" placeholder="请输入部门名称（必填）" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="branchDesc" class="col-xs-4 control-label text-right">部门描述</label>
                            <div class="col-xs-6">
                                <input type="text" class="form-control" ms-duplex="BranchData.DeptDesc" id="branchDesc" placeholder="请输入部门描述" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="branchShort" class="col-xs-4 control-label text-right">房间号</label>
                            <div class="col-xs-6">
                                <input type="text" class="form-control" ms-duplex="BranchData.RoomCode" placeholder="请输入房间号" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="branchShort" class="col-xs-4 control-label text-right">排序</label>
                            <div class="col-xs-6">
                                <input type="text" class="form-control" ms-duplex="BranchData.DeptShort" id="branchShort" placeholder="请输入部门排序" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="BranchAdd()"><i class="fa fa-spinner fa-spin" style="display: none"></i>确&nbsp;&nbsp;认</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var tempindex = avalon.define({
        $id: "YGINDEX",
        BranchListData: [],
        UserData: [],
        searchContent: "",
        SelDeptItem: {},
        selNum: function (item) {    //选择显示的条数
            model.page.pagecount = item;
            tempindex.GetLIST();
        },
        InitWigetData: function () {
            model.ShowColumns.clear();
            model.ShowColumns.pushArray([
                { "ColName": "DeptName", "ColText": "部门", "IsSel": true, "format": "text" },
                { "ColName": "zhiwu", "ColText": "职务", "IsSel": true, "format": "text" },
                { "ColName": "mobphone", "ColText": "手机", "IsSel": true, "format": "text" },
                { "ColName": "isgz", "ColText": "关注状态", "IsSel": false, "format": "gzstatus" },
                { "ColName": "telphone", "ColText": "座机", "IsSel": false, "format": "text" },
                { "ColName": "mailbox", "ColText": "邮箱", "IsSel": false, "format": "text" },
                { "ColName": "RoomCode", "ColText": "房间号", "IsSel": false, "format": "text" },
                { "ColName": "Usersign", "ColText": "职责", "IsSel": false, "format": "text", "len": 15 },
                { "ColName": "Sex", "ColText": "性别", "IsSel": false, "format": "text" },
                { "ColName": "weixinCard", "ColText": "微信号", "IsSel": false, "format": "text" },
                { "ColName": "NickName", "ColText": "昵称", "IsSel": false, "format": "text" },
                { "ColName": "JobNum", "ColText": "工号", "IsSel": false, "format": "text" },
                { "ColName": "QQ", "ColText": "QQ", "IsSel": false, "format": "text" },
                { "ColName": "IDCard", "ColText": "身份证", "IsSel": false, "format": "text" },
                { "ColName": "Nationality", "ColText": "籍贯", "IsSel": false, "format": "text" },
                { "ColName": "Nation", "ColText": "民族", "IsSel": false, "format": "text" },
                { "ColName": "HomeAddress", "ColText": "家庭住址", "IsSel": false, "format": "text" },
                { "ColName": "GSPhone", "ColText": "公司电话", "IsSel": false, "format": "text" },
                { "ColName": "EntryDate", "ColText": "入职时间", "IsSel": false, "format": "dateformat" },
                { "ColName": "DepartureDate", "ColText": "离职时间", "IsSel": false, "format": "dateformat" },
                { "ColName": "Birthday", "ColText": "生日", "IsSel": false, "format": "dateformat" },
                { "ColName": "Marriage", "ColText": "婚姻状况", "IsSel": false, "format": "text" },
                { "ColName": "Children", "ColText": "子女", "IsSel": false, "format": "text" },
                { "ColName": "JJLXR", "ColText": "紧急联系人", "IsSel": false, "format": "text" },
                { "ColName": "JJLXRDH", "ColText": "紧急联系人电话", "IsSel": false, "format": "text" },
                { "ColName": "Hire", "ColText": "雇佣方式", "IsSel": false, "format": "text" },
                { "ColName": "ZZTime", "ColText": "转正时间", "IsSel": false, "format": "dateformat" },
                { "ColName": "ContractSTime", "ColText": "劳动合同开始时间", "IsSel": false, "format": "dateformat" },
                { "ColName": "ContractETime", "ColText": "劳动合同结束时间", "IsSel": false, "format": "dateformat" },
                { "ColName": "SocialInsurance", "ColText": "社保号码", "IsSel": false, "format": "text" },
                { "ColName": "GJJID", "ColText": "公积金账号", "IsSel": false, "format": "text" },
                { "ColName": "BankCard", "ColText": "银行卡号", "IsSel": false, "format": "text" },
                { "ColName": "BankName", "ColText": "银行名称", "IsSel": false, "format": "text" },
            ]);
            tempindex.GetBranch();
            ComFunJS.initForm();
        },
        ConBranch: function (str) {
            if (str.length > 12) {
                str = str.substring(0, 12) + "...";
            }
            return str;
        },
        GetBranch: function () {
            $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETALLBMNEW', {}, function (resultData) {
                tempindex.BranchListData = resultData.Result;
                tempindex.SelDeptItem = resultData.Result[0];
                tempindex.GetLIST();
            })
        },
        BranchToggle: function (dom, event) {
            if (event) {
                event.stopPropagation();
            }
            if (dom) {
                $(".jg-item b i").removeClass("active");
                if ($(dom).parent().parent().next(".children-list").css("display") == "none") {
                    $(dom).addClass("active");
                }
                $(dom).parent().parent().next(".children-list").slideToggle('fast');
            }
        },
        BranchClick: function (item, event) {
            if (event) {
                event.stopPropagation();
            }
            tempindex.SelDeptItem = {};
            tempindex.SelDeptItem = item.$model;
            tempindex.GetLIST();
        },
        dcyg: function () {
            if (model.page.total > 0) {
                $(this).attr("href", "/API/VIEWAPI.ashx?Action=XTGL_EXPORTYG&P1=" + tempindex.SelDeptItem.DeptCode + "&P2=" + tempindex.searchContent + "&pagecount=" + model.page.total);
            }
            else {
                ComFunJS.winwarning("无数据");
            }
        },
        totalUserCount: 0,
        GetLIST: function () {
            $(".icheckbox_square-blue", $("#branchTab")).removeClass('checked')//去除选中
            $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETUSERBYCODENEW_PAGE', { "P1": tempindex.SelDeptItem.DeptCode, P2: tempindex.searchContent, pagecount: model.page.pagecount, p: 1 }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    tempindex.UserData = resultData.Result;
                    model.page.total = resultData.Result2;
                    if (tempindex.UserData.size() == 0) { model.isnull = true; } else { model.isnull = false; }
                    tempindex.totalUserCount = resultData.Result2;
                    var page = 1;
                    laypage({
                        cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                        //  pages: resultData.Result1, //通过后台拿到的总页数
                        pages: Math.ceil(parseInt(resultData.Result2) * 1.0 / model.page.pagecount), //通过后台拿到的总页数
                        curr: 1, //初始化当前页
                        skin: 'molv',
                        jump: function (e) { //触发分页后的回调
                            if (e.curr != page) {
                                $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETUSERBYCODENEW_PAGE', { "P1": tempindex.SelDeptItem.DeptCode, P2: tempindex.searchContent, pagecount: model.page.pagecount, p: e.curr }, function (resultData) {
                                    tempindex.UserData = resultData.Result;
                                    tempindex.totalUserCount = resultData.Result2;
                                })
                                page = e.curr;
                            }
                        }
                    });
                }
            })
        },
        UserPrintData: [],
        branchLeader: "",
        OpenSetLeader: function () {

            $('#BranchLeadModal').modal('show');
            tempindex.branchLeader = tempindex.SelDeptItem.BranchLeader;
            ComFunJS.initForm();
        },
        SetLeader: function () {
            $.post("/API/VIEWAPI.ashx", { Action: "XTGL_SETBRANCHLEADER", P1: tempindex.branchLeader, P2: tempindex.SelDeptItem.DeptCode },
            function (result) {
                if ($.trim(result.ErrorMsg) != "") {
                    top.ComFunJS.winwarning(result.ErrorMsg);
                } else {
                    tempindex.SelDeptItem.BranchLeader = tempindex.branchLeader;
                    top.ComFunJS.winsuccess("设置负责人成功");
                    $('#BranchLeadModal').modal('hide');
                }

            });
        }, userLead: "",
        selUserName: "",
        OpenUserLead: function (item) {
            $('#UserLeadModal').modal('show');
            tempindex.selUserName = item;
            tempindex.userLead = item.UserLeader;
            ComFunJS.initForm();
        },
        SetUserLeader: function () {
            $.post("/API/VIEWAPI.ashx", { Action: "XTGL_SETUSERLEADER", P1: tempindex.userLead, P2: tempindex.selUserName.UserName },
           function (result) {
               if ($.trim(result.ErrorMsg) != "") {
                   top.ComFunJS.winwarning(result.ErrorMsg);
               } else {
                   top.ComFunJS.winsuccess("设置上级成功");
                   tempindex.selUserName.UserLeader = tempindex.userLead;
                   $('#UserLeadModal').modal('hide');
               }
           })
        },
        EditUser: function (item) {
            ComFunJS.winviewform("/ViewV5/AppPage/APP_ADD_WF.html?FormCode=XTGL_YGGL&ID=" + item.UserName + "&userName=" + item.UserName, '编辑员工', "1000", "");
        },
        DelDept: function (item, event) {
            if (event) {
                event.stopPropagation();
            }
            if (confirm("确定要删除" + item.DeptName + "吗？")) {
                $.getJSON("/API/VIEWAPI.ashx", { Action: "XTGL_DELBRANCH", P1: item.DeptCode },
                function (result) {
                    if (result.ErrorMsg == "") {
                        model.refpage('YGINDEX');

                    }
                });
            }
        },
        DelUser: function (item) {
            if (confirm("确定要删除" + item.UserName + "吗？")) {
                $.post("/API/VIEWAPI.ashx", { Action: "XTGL_DELUSER", P1: item.UserName },
                function (result) {
                    if ($.trim(result.ErrorMsg) == "") {

                        tempindex.UserData.remove(item);
                        top.ComFunJS.winsuccess("操作成功");

                    }
                });
            }
        },
        EditIsUse: function (item) {
            $.post("/API/VIEWAPI.ashx", { Action: "XTGL_UPDATEUSERISUSE", P1: item.UserName, P2: (item.IsUse == "Y" ? "N" : "Y") },
              function (result) {
                  if ($.trim(result.ErrorMsg) == "") {

                      top.ComFunJS.winsuccess(item.IsUse == "Y" ? "禁用成功" : "启用成功");
                      tempindex.BranchClick(tempindex.SelDeptItem, null);
                  }
              });
        },
        UserAdd: function () {
            var deptCode = tempindex.SelDeptItem.DeptCode;
            if (!deptCode) {
                deptCode = 1;
            }
            if ($.trim(deptCode) != "") {

                top.ComFunJS.winviewform("/ViewV5/AppPage/APP_ADD_WF.html?FormCode=XTGL_YGGL&branchNo=" + deptCode, '添加表单', "1000", "");
            }
        },
        UserImport: function () {
            top.ComFunJS.winviewform("/ViewV5/AppPage/XTGL/IMPORTUSER.html", "导入用户", 1000, 600);
        },
        setBranch: function (item) {//用户信息或部门信息，设置类型：user/branch
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/XTGL/TopBranchSelect.html?checkvalue=" + item.TXLQX + "&hasQX=" + item.IsHasQX, "选择部门", 500, 470, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var branch = ComFunJS.isIE() ? top.window.frames[frameid].getselectedbranch() : top.window.frames[frameid].contentWindow.getselectedbranch();
                var id = item.DeptCode;
                $.post("/API/VIEWAPI.ashx", { Action: "XTGL_SETBRANCHQX", P1: branch.branchid, P2: id, qx: branch.ishasqx },
                    function (result) {
                        if ($.trim(result.ErrorMsg) == "") {

                            item.TXLQX = branch.branchid;
                            item.IsHasQX = branch.ishasqx;
                            top.layer.close(index)
                            top.ComFunJS.winsuccess("设置成功");
                        }
                    });
            })
        },
        UPDATEUser: function (item) {
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/XTGL/BranchSelect.html?checkvalue=" + item.BranchCode, "修改部门", 500, 470, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var branch = ComFunJS.isIE() ? top.window.frames[frameid].getselectedbranch() : top.window.frames[frameid].contentWindow.getselectedbranch();
                item.BranchCode = branch.branchid;
                var modelValue = JSON.stringify(item.$model);
                $.post("/API/VIEWAPI.ashx", { Action: "XTGL_ADDUSER", P1: modelValue },
                     function (result) {
                         if ($.trim(result.ErrorMsg) == "") {
                             item.DeptName = branch.branchname;
                             top.layer.close(index)
                             top.ComFunJS.winsuccess("设置成功");
                         }
                     });
            })
        },
        UPDATEPLUser: function () {
            var userNames = $("#branchTab tbody tr td .checked");
            if (userNames.length == 0) {

                top.ComFunJS.winwarning("请选择要修改的用户");
                return;
            }
            top.ComFunJS.winbtnwin("/ViewV5/AppPage/XTGL/BranchSelect.html", "批量修改部门", 500, 470, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var branch = ComFunJS.isIE() ? top.window.frames[frameid].getselectedbranch() : top.window.frames[frameid].contentWindow.getselectedbranch();
                var strUser = ""
                $(userNames).each(function (i, item) {
                    strUser += $(item).attr("user") + ",";
                })
                strUser = strUser.substring(0, strUser.length - 1);
                if (strUser) {
                    $.post("/API/VIEWAPI.ashx", { Action: "XTGL_PLSETBRANCH", P1: strUser, P2: branch.branchid },
                         function (result) {
                             if ($.trim(result.ErrorMsg) == "") {
                                 tempindex.BranchClick(tempindex.SelDeptItem, null);
                                 top.layer.close(index)
                                 top.ComFunJS.winsuccess("设置成功");
                             }
                         });
                }
            })
        },
        resetUser: "",
        OpenModify: function (user) {
            tempindex.resetUser = user.UserName;
            $('#ReSetPassWordModal').modal('show');
        },
        OpenPLModify: function () {
            var userNames = $("#branchTab tbody tr td .checked");
            if (userNames.length == 0) {

                top.ComFunJS.winwarning("请选择要重置的用户");
                return;
            }
            var strUser = ""
            $(userNames).each(function (i, item) {
                strUser += $(item).attr("user") + ",";
            })
            strUser = strUser.substring(0, strUser.length - 1);
            if (strUser) {
                tempindex.resetUser = strUser;
                $('#ReSetPassWordModal').modal('show');
            }
        },
        ModifyPwd: function () {
            var pwd = $("#newPwd").val();
            var pwd2 = $("#newPwd2").val();
            var retmsg = "";
            if ($("#ReSetPassWordModal .szhl_require")) {
                $("#ReSetPassWordModal .szhl_require").each(function () {
                    if ($(this).val() == "") {
                        retmsg = $(this).parent().find("label").text() + "不能为空";
                    }
                })
            }
            if (retmsg !== "") {
                top.ComFunJS.winwarning(retmsg);
                return;
            }
            if (pwd != pwd2) {
                retmsg = "确认密码不一致";
                top.ComFunJS.winwarning(retmsg);
                return;
            }
            $.post("/API/VIEWAPI.ashx?Action=XTGL_MODIFYPWD", { P1: pwd, P2: pwd2, username: tempindex.resetUser }, function (result) {
                if ($.trim(result.ErrorMsg) == "") {

                    top.ComFunJS.winsuccess("操作成功");
                    $('#ReSetPassWordModal').modal('hide');
                }
            });
            $("#newPwd").val("");
            $("#newPwd1").val("");
        },
        BranchData: { "DeptName": "", DeptDesc: "", DeptShort: "0", DeptRoot: "", RoomCode: "" },
        OpenBranch: function (type, branch, pbranch) {
            if (type == 1)//添加部门
            {
                tempindex.BranchData = { DeptName: "", DeptDesc: "", DeptShort: "0", DeptRoot: branch.DeptCode, RoomCode: "" };
                $("#pname").val(branch.DeptName);
            } else {
                if (branch.DeptCode) {
                    //获取主要菜单
                    $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETBRANCHBYCODE', { "P1": branch.DeptCode }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            tempindex.BranchData = resultData.Result;
                            $("#pname").val(resultData.Result1.DeptName);
                        }
                    })
                }
            }
            $('#ModifyBranchModal').modal('show');
        },
        BranchAdd: function () {
            if (!tempindex.BranchData.DeptName) {
                ComFunJS.winwarning("请输入部门名称");
                return;
            }
            var reg = /^\d+$/;
            if (!tempindex.BranchData.DeptShort) {
                ComFunJS.winwarning("请输入部门排序");
                return;
            }
            if (!reg.test(tempindex.BranchData.DeptShort)) {
                ComFunJS.winwarning("排序必须为数字");
                return;
            }
            var modelValue = JSON.stringify(tempindex.BranchData.$model);
            $.post("/API/VIEWAPI.ashx", { Action: "XTGL_ADDBRANCH", P1: modelValue },
            function (result) {
                if ($.trim(result.ErrorMsg) == "") {
                    ComFunJS.winsuccess("操作成功");
                    $('#ModifyBranchModal').modal('hide');
                    model.refpage('YGINDEX');
                }
            });
        },
        gzStatus: function (type) {
            var typeName = "未关注";
            if (type == 1) {
                typeName = "已关注";
            }
            return typeName;
        }, TBGZSTATUS: function () {
            $.getJSON('/API/VIEWAPI.ashx?Action=INIT_TBGZSTATUS', {}, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    top.ComFunJS.winsuccess("同步成功");
                    tempindex.GetLIST();
                }
            })

        },
    });

    function jptj(event) {
        if (event.keyCode == 13 || event.keyCode == 10) {
            tempindex.GetLIST();
        }
    }
    //# sourceURLYGINDEX.js;
</script>
